import { post } from '@/utils/request'

// 定义接口响应类型
export interface AuthResponse {
  token?: string
  message?: string
  user_id?: number
}

// 用户接口
export interface User {
  id: number
  username: string
  role: number
  created_at: string
  updated_at: string
}

// 用户注册参数
export interface RegisterParams {
  username: string
  password: string
  role?: number
}

// 用户登录参数
export interface LoginParams {
  username: string
  password: string
}

// 修改密码参数
export interface ChangePasswordParams {
  old_password: string
  new_password: string
}

// 用户注册
export function register(data: RegisterParams): Promise<AuthResponse> {
  return post<AuthResponse>('/auth/register', data)
}

// 用户登录
export function login(data: LoginParams): Promise<AuthResponse> {
  return post<AuthResponse>('/auth/login', data)
}

// 用户登出
export function logout(): Promise<AuthResponse> {
  return post<AuthResponse>('/auth/logout')
}

// 修改密码
export function changePassword(data: ChangePasswordParams): Promise<AuthResponse> {
  return post<AuthResponse>('/auth/change-password', data)
} 